/*************************************
 **   @author: 野狼上校               **
 **   @create: 2024-04-03 12:07      **
 **   @version: 1.0                  **
 *************************************/
/**  验证规则 **/

/*用户名验证规则*/
export const validatorUsername = (rule: any, value: any, callback: any) => {
    if (value == '') {
        callback(new Error("账号不能为空"));
    }
    if (value.length < 1 || value.length > 13) {
        callback(new Error("账号必须在2-12个字符之间"));
    }
    callback();
}

/*密码验证规则*/
export const validatorPassword = (rule: any, value: any, callback: any) => {
    if (value == '') {
        callback(new Error("密码不能为空"));
    }
    if (value.length < 5 || value.length > 19) {
        callback(new Error("密码必须在6-18个字符之间"));
    }
    callback();
}

/*手机号码验证规则*/
export const validatorPhone = (rule: any, value: any, callback: any) => {
    if (value == '') {
        callback(new Error("手机号码不能为空"));
    }
    if (value.length < 5 || value.length > 19) {
        callback(new Error("手机号码必须是11位"));
    }
    //11位手机号码正则
    const reg_phone = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
    if (!reg_phone.test(value)) {
        callback(new Error("请输入合法的手机号码"))
    }
    callback();
}

/*选择框验证*/
export const validatorSelect = (rule: any, value: any, callback: any) => {
    if (value == '') {
        callback(new Error("选项不能为空"));
    }
    callback();
}

/*一般输入框*/
export const validatorInput = (rule: any, value: any, callback: any) => {
    if (value == '') {
        callback(new Error("输入不能为空"));
    }
    callback();
}

/*首字母（长度只能为1,而且是字母）*/
export const validatorInitial = (rule: any, value: any, callback: any) => {
    if (value == '') {
        callback(new Error("输入不能为空"));
    }
    if (value.length != 1) {
        callback(new Error(""));
    }
    //只能是长度为1,且必须是字母正则
    const reg_initial = /^[a-zA-Z]$/;
    if (!reg_initial.test(value)) {
        callback(new Error("只能是长度为1,且必须是字母"))
    }
    callback();
}